<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .wrapper {
        width: 100vw;
        height: 100vh;
        overflow: auto;
      }
      .content {
        height: 2000px;
      }
      #box {
        width: 100px;
        height: 100px;
        background: red;
      }
    </style>
  </head>
  <body>
    <div class="wrapper">
      <div class="content"></div>
      <div id="box" data-id="1"></div>
    </div>
    <script>
      // 选择需要观察变动的节点
      const targetNode = document.getElementById("box");
      const wrapper = document.querySelector(".wrapper");
      var io = new IntersectionObserver((entries) => {
        console.log(entries);
      });
      io.observe(document.getElementById("box"));
    </script>
  </body>
</html>
